#import "PhotosAlbum.h"

@implementation PhotosAlbum
- (void) imageSaved: (UIImage *) image imageFinishSavingWithError:(NSError *)error contextInfo: (void *) contextInfo
{
    NSLog(@"保存结束");
    if (error != nil)
    {
        NSLog(@"有错误");
    }
}
- (void)videoSaved:(NSString *)videoPath videoFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    if (error)
    {
        NSLog(@"保存视频失败：%@", error);
    }
    else
    {
        NSLog(@"保存视频成功");
    }
}
@end

extern "C"
{
    void _CopyImageToPhotosAlbum(char *path)
    {
        NSString *strReadAddr = [NSString stringWithUTF8String:path];
        UIImage *img = [UIImage imageWithContentsOfFile:strReadAddr];
        PhotosAlbum *instance = [PhotosAlbum alloc];
        UIImageWriteToSavedPhotosAlbum(img, instance, @selector(imageSaved:imageFinishSavingWithError:contextInfo:), nil);
    }
    void _CopyVideoToPhotosAlbum(char *path)
    {
        NSString *videoPath = [NSString stringWithUTF8String:path];
        BOOL videoCompatible = UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(videoPath);
        //检查视频能否保存至相册
        if (videoCompatible)
        {
            PhotosAlbum *instance = [PhotosAlbum alloc];
            UISaveVideoAtPathToSavedPhotosAlbum(videoPath, instance, @selector(videoSaved:videoFinishSavingWithError:contextInfo:), nil);
        }
        else
        {
            NSLog(@"该视频无法保存至相册");
        }
    }
}